package edu.wisc.hevea.launcher;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class BrokerLauncher implements Runnable {

	private static final String BROKER_CMD_PATH = "/home/anand/Documents/DistributedSystems/HeveaLibraries/broker.jar";

	private String hostName;
	private int port;

	public BrokerLauncher(String hostName, int port) {
		this.hostName = hostName;
		this.port = port;
	}

	@Override
	public void run() {
		String[] exec = new String[] { "java", "-jar", BROKER_CMD_PATH,
				String.format("%s:%d", hostName, port) };
		try {
			Process brokerProcess = Runtime.getRuntime().exec(exec);
			
			String line = "";
			BufferedReader in = new BufferedReader(new InputStreamReader(
					brokerProcess.getInputStream()));
			while ((line = in.readLine()) != null) {
				// System.out.println(line);
			}
			in.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
